
package neteasefilters.filters;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class CvHudson implements IImageFilter {

    int res;
    Context c;

    public CvHudson(Context in, int res) {
        c = in;
        this.res = res;
    }

    @Override
    public Image process(Image inImg) {
        int w = inImg.getWidth();
        int h = inImg.getHeight();

        Bitmap brg = BitmapFactory.decodeResource(c.getResources(), res);
        if (brg.getWidth() != w || brg.getHeight() != h) {
            brg = Bitmap.createScaledBitmap(brg, w, h, false);
        }
        int[] overPix = new int[w * h];
        brg.getPixels(overPix, 0, w, 0, 0, w, h);
        brg.recycle();
        brg = null;
        System.gc();

        inImg.updateColorArray();
        int[] pix = inImg.getColorArray();

        LibCvFilter.CvHudson(pix, overPix, w, h);
        inImg.setColorArray(pix);

        overPix = null;
        System.gc();

        return inImg;
    }
}
